package com.wswy.wzcx.widget.home;

import android.content.Context;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.util.Log;

import com.facebook.common.util.UriUtil;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.wswy.wzcx.R;

@Deprecated
public class RedPacketView extends SimpleDraweeView {

  private static final String TAG = "RedPacketView";

  public RedPacketView(Context context) {
    this(context,null);
  }

  public RedPacketView(Context context, AttributeSet attrs) {
    this(context, attrs,0);
  }

  public RedPacketView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);


    init(context);
  }

  private boolean showing = false;

  private void init(Context context){

//    setImageResource(R.drawable.red_envelope1);


//    start();

  }


  public void start(){
    if(!showing){
      showing = true;
      DraweeController controller =
              Fresco.newDraweeControllerBuilder()
                      .setUri(UriUtil.parseUriOrNull("asset:///redPacket.webp"))
                      .setAutoPlayAnimations(true)
                      .build();

      setController(controller);
//      postDelayed(runnable1,200);
    }
  }

  public void stop(){
    showing = false;
  }


//  private Runnable runnable1 = new Runnable() {
//    @Override
//    public void run() {
//      setImageResource(R.drawable.red_envelope1);
//
//      if(showing){
//        postDelayed(runnable2,200);
//      }
//    }
//  };
//
//  private Runnable runnable2 = new Runnable() {
//    @Override
//    public void run() {
//      setImageResource(R.drawable.red_envelope2);
//      if(showing){
//        postDelayed(runnable1,200);
//      }
//    }
//  };

  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    start();
  }

  @Override
  protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    showing = false;
  }
}
